<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/allApp.css" />
		<link rel="stylesheet" href="../css/css.css" />
		<style type="text/css">
			body,.mui-content{
				background-color: #ffffff;
			}
			.mui-left.title {
				margin: 0;
				width: 78%;
			}

			.xj-content .mui-card-content {
				padding: 2px 2px 10px 2px;
			}

			.mui-card label {
				padding: 0;
			}

			.mui-content {
				padding-bottom: 70px;
			}

			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 30px;
			}

			.footerFix .mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}

			.footerFix {
				position: fixed;
				background: #fff;
				width: 100%;
				padding: 10px 0;
				bottom: 0;
				box-shadow: 0 -1px 6px #ccc;
				display: flex;
				align-items: center;
			}

			.footer-button {
				text-align: right;
			}
			.textalign {
				text-align: center;
			}

			.footer-button button {
				padding: 8px 17px;
				margin-right: 10px;
				border: 0px;
				border:1px solid #cccccc;
			}
			.tjxj {
				/* margin-right: 5px; */
				border: 1px solid #cccccc;
				height: 34px;
				/* margin-top: 5px; */
				line-height: 34px;
				font-size: 13px;
				border-radius: 3px;
				width: 80px;
				text-align: center;
				position: absolute;
				right: 5px;
				top: 5px;
			}
			.tj2{
				position:absolute;
				right:21px;
				top:5px;
				padding:5px 0px;
				width: 70px;
				text-align: center;
			}
			.tj{
				position:absolute;
				right:21px;
				top:22px;
				padding:5px 0px;
				width: 70px;
				text-align: center;
			}
			.addtj{
				border:1px solid #cccccc;
				border-radius: 3px;
				color: #A4A4A4;
				padding: 2px 0px;
			}
			.wxj-list{
				width: 90%;
				margin-left: 5%;
				border-bottom: 1px solid #EEEEEE;
			}
			.mui-card-content{
				border-bottom: 0px!important;
			}
			.padleft38{
				padding-left: 30px!important;
			}
			.martop10{
				margin-top: 10px;
			}
			.titlesize{
				font-size: 14px!important;
			}
			.wxjflex{
				display: flex;
				flex-direction: column;
			}
			.wifi {
				width: 80%;
				margin: 100px auto;
				text-align: center;
			}
			
			.wifi img {
				width: 80%;
				margin-right: 20px;
			}
			
			.wifi p {
				font-size: 1rem;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" style="width: 65%;"></h1>
			<span class="mui-pull-right tjxj" style="color: #FFF" id="tjxjj">完成巡检</span>
		</header>
		<div class="mui-content" id="content">
			<div class="xj-content" id="yulan" style="margin-bottom: 50px;">

				<div class="mui-card" style="position:relative" v-for="(item,index) in data" :key="index">
					<div class="mui-input-row mui-checkbox wxj-list">
						<label class="padleft38">
							<div class="mui-card-header">
								<div class="mui-left title titlesize">设备名称：{{item.name}}</div>
							</div>
							<div class="mui-card-content">
								<p class="titlesize">设备编号：<span class="beizhu">{{item.number}}</span></p>
							</div>
						</label>
						<input name="checkbox" v-if="item.status == 0" :checked="false"  :data-id="(item.id)" style="left: 0px;" value="Item 2" type="checkbox" >
						<input name="checkbox" v-else disabled="true" :checked="true" style="left: 0px;" value="Item 2" type="checkbox" >
					</div>
					<div class="tj2 wxjflex"  v-if="item.status == 0">
						<span class="tjbtn addtj" :data-id="(item.id)" v-if="scantype">跳检</span>
						<!-- <span class="xjbtn addtj martop10" :data-code="(item.number)" :data-id="(item.id)" :data-xsdwindid="(item.xsd_wind_id)" >巡检</span> -->
					</div>
					<div class="tj" v-if="item.status == 5">已跳检</div>
					<div :data-id="(item.id)" :data-type="(item.type)"  v-if="item.status == 1 || item.status == 2" class="tj xjover">完成</div>
				</div>
				<div class="wifi" v-if="data.length==0"><img src="./../img/empty_data.png"/><p>亲，这里没有数据了哦~</p></div>
				<!-- <div class="mui-card" style="position:relative">
					<div class="mui-input-row mui-checkbox wxj-list">
						<label  class="padleft38">
							<div class="mui-card-header">
								<div class="mui-left title">地点</div>
							</div>
							<div class="mui-card-content">
								<p>设备编号:<span class="beizhu">12</span></p>
							</div>
						</label>
						<input name="checkbox"  style="left: 0px;" value="Item 2" type="checkbox" data-id="12">
					</div>
					<div class="tjbtn tj"  data-id="12">已跳检</div>
				</div>
				<div class="mui-card" style="position:relative">
					<div class="mui-input-row mui-checkbox wxj-list">
						<label  class="padleft38">
							<div class="mui-card-header">
								<div class="mui-left title">地点</div>
							</div>
							<div class="mui-card-content">
								<p>设备编号:<span class="beizhu">12</span></p>
							</div>
						</label>
						<input name="checkbox"  style="left: 0px;" value="Item 2" type="checkbox" data-id="12">
					</div>
					<div class="xjover tj"  data-id="12">完成</div>
				</div> -->

			</div>
		</div>
		<div class="footerFix mui-row" >
			<div class="mui-input-row mui-checkbox mui-left mui-col-sm-4 mui-col-xs-4">
				<label id="text">全选</label>
				<input name="checkbox" value="Item 2" type="checkbox" id="checkAll">
			</div>
			<div class="mui-col-sm-4 mui-col-xs-4 textalign" id="scan">
				<img src="../img/Scan.png"  style="width: 80px;height: 80px;"/>
			</div>
			<div class="mui-col-sm-4 mui-col-xs-4 footer-button">
				<button id="sure">
					批量跳检
				</button>
			</div>
		</div>
		<script src="../../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../../js/vue.js"></script>
		<script type="text/javascript" src="../../../js/mkeyplus.base.xunjian.js"></script>
		<script type="text/javascript" src="../../../js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="../../../js/common.js"></script>
		<script type="text/javascript" src="../../../js/uuid.js"></script>
		<script type="text/javascript">
			mui.init();
			var xsdwindid = "";
			var rate = "";
			var wind = "";
			var xjtype = "";
			window.vm = new Vue({
				el: "#content",
				data: {
					data: [],
					
				}
			});
			
			mui.plusReady(function() {
				wind = localStorage.getItem('org_code'); //获取缓存中的风场编号
				wind = JSON.parse(wind);
				self = plus.webview.currentWebview();
				xsdwindid = self.sbid;
				rate = self.rate;
				xjtype = self.xjtype;
				
				document.querySelector('.mui-title').innerText = self.title
				console.log('xsdwindid='+xsdwindid);
				getData('init');
				// getHelpStatus();
			})
			
			window.addEventListener('refresh', function(e){//执行刷新
				//刷新子表
			    getData('refresh');
			});
			
			function getHelpStatus(){
				mui.baseApp.httpRequst('/api/v2/sbxj/findHelperXjStatus', {
						xsdWindId:xsdwindid,
						memberId:localStorage.getItem('userid')
					},
					function(res) {
						vm.scantype = res.data.status;
						console.log('vm.scantype='+vm.scantype);
						if(!res.data.status){
							document.querySelector('.footerFix').style.display = 'none';
							document.getElementById('tjxjj').style.display = 'none';
						}
						getData('init');
					}
				);
			}
			
			function getData(type) {
				if(type == 'init'){
					plus.nativeUI.showWaiting('列表加载中...');
				}
				mui.baseApp.httpRequst('/api/v2/sbxj/notXjListByXsdWind', {
						wind:wind,
						xsdWindId:xsdwindid,
						memberId:localStorage.getItem('userid')
					},
					function(res) {
						vm.scantype = res.data.isXunjian;
						console.log('vm.scantype='+vm.scantype);
						if(!res.data.isXunjian){
							document.querySelector('.footerFix').style.display = 'none';
							document.getElementById('tjxjj').style.display = 'none';
						}
						
						dataArr = [];
						plus.nativeUI.closeWaiting();
						console.log('2........'+JSON.stringify(res));
						vm.data = res.data.list;
						//刷新待巡检列表，改变状态
						var opener = plus.webview.currentWebview().opener();
						mui.fire(opener, 'refresh');
					}
				);
			}
			
			var dataArr = [];
			//实现全选反选
			$("#checkAll").on('click', function() {
				var value = this.checked ? "true" : "false";
				dataArr = [];
				$(".mui-content input:checkbox").each(function() {

					if (!$(this).is(':disabled')) {
						$(this).prop('checked', $("#checkAll").prop('checked'));
					}
				})
				if (value == "true") {
					$("#text").text("全不选");
				} else {
					$("#text").text("全选");
				}
				
				console.log($(".mui-content input:checked").length);
				for (var i = 0; i < $(".mui-content input:checked").length; i++) {
					if(!$(".mui-content input:checked").eq(i).is(':disabled')){
						var id = $(".mui-content input:checked").eq(i).attr('data-id');
						dataArr.push(id)
					}
				}
				console.log('dataArr' + dataArr)
			})
			//完成巡检
			document.getElementById('tjxjj').addEventListener('tap', function() {
				mui.baseApp.httpRequst('/api/v2/sbxj/endXsdWind', {
						xsdWindId:xsdwindid
					},
					function(res) {
						mui.toast(res.message);
						console.log(JSON.stringify(res));
						if(res.status == '200'){
							plus.webview.currentWebview().close();
							var page1 = null;
							if(xjtype == 'pinci'){
								page1 = plus.webview.getWebviewById('dxjchild/syz_sub.html');
								deletePc();
								deletePcChild();
							}else{
								page1 = plus.webview.getWebviewById('dxjchild/xl_sub.html');
								deleteXl();
								deleteXlChild();
							}
							
							mui.fire(page1, 'refresh');
						}else{
							mui.toast(res.message);
						}
					}
				);
			})
			//扫码
			document.querySelector('#scan').addEventListener('tap', function() {
				mui.openWindow({
					id: "coder.html",
					url: "coder.html",
					extras: {
						type: rate,
						xsdwindid:xsdwindid,
						offlinetype:xjtype
					},
					waiting: {
						autoShow: false
					}
				});
			})
			//跳检
			$(".mui-content").on("tap", ".tjbtn", function() {
				var id = $(this).attr('data-id');
				dataArr.push(id);
				mui.openWindow({
					id: "reason.html",
					url: "reason.html",
					waiting: {
						autoShow: false, //自动显示等待框，默认为true
					},
					extras: {
						Idarr: dataArr,
						xjtype:xjtype,
						xsdwindid:xsdwindid
					}
				});
			})
			//巡检
			$(".mui-content").on("tap", ".xjbtn", function() {
				var smTime = getTime();
				localStorage.setItem("curentTime",smTime);
				var id = $(this).attr('data-id');
				var xsdwindid = $(this).attr('data-xsdwindid');
				var scancode = $(this).attr('data-code');
				dataArr.push(id);
				mui.openWindow({
					id: "xianchangxunjian.html",
					url: "../xianchangxunjian.html",
					extras: {
						scancode: scancode,
						index: rate,
						smTime: smTime,
						xsdwindid:xsdwindid,
						from:'news'
					}
				});
			})
			//巡检完成详情
			$(".mui-content").on("tap", ".xjover", function() {
				var Type = $(this).attr('data-type');
				var id = $(this).attr('data-id');
				mui.openWindow({
					url: '../yulan.html',
					id: 'yulan.html',
					extras: {
						_id: id,
						Type: Type
					},
					createNew: false
				})
			})


			$(".mui-content").on('change', "input:checkbox", function() {
				console.log('dataArr' + dataArr);
				var value = this.checked ? "true" : "false";
				var id = $(this).attr('data-id');
				var i = 0;
				$(".mui-content input:checkbox").each(function() {

					if (!$(this).is(':disabled')) {
						i++;
					}
				})
				//当选中的长度等于checkbox的长度的时候,就让控制全选反选的checkbox设置为选中,否则就为未选中
				if (i === $(".mui-content input:checked").length) {
					$("#checkAll").prop("checked", true);
					$("#text").text("全不选");
				} else {
					$("#checkAll").prop("checked", false);
					$("#text").text("全选");
				}
				if (value == "true") {

					dataArr.push(id);
					//					userIds.push(id);
					console.log("添加后。。。" + JSON.stringify(dataArr));
				} else {

					for (var i = 0; i < dataArr.length; i++) {
						if (dataArr[i] == id) {
							dataArr.splice(i, 1);
						}
					}
					console.log("移除后。。。" + JSON.stringify(dataArr));
				}
			})
			
			function deletePc(){
				var pc = plus.storage.getItem('pc');
				console.log('频次.....'+JSON.stringify(pc));
				pc = JSON.parse(pc);
				if(pc){
					for(var m = 0; m < pc.length; m++) {
						if(pc[m].id == xsdwindid) {
							pc.splice(m, 1);
							plus.storage.setItem('pc', JSON.stringify(pc));
						}
					}
				}
			}
			
			function deletePcChild(){
				var pcchild = plus.storage.getItem('pcchild');
				pcchild = JSON.parse(pcchild);
				if(pcchild){
					for(var i = 0; i < pcchild.length; i++) {
						if(pcchild[i].key == xsdwindid) {
							pcchild.splice(i, 1);
							plus.storage.setItem('pcchild', JSON.stringify(pcchild));
						}
					}
				}
				console.log('频次.....'+JSON.stringify(pcchild));
			}
			
			function deleteXl(){
				var xl = plus.storage.getItem('xl');
				console.log('线路.....'+JSON.stringify(xl));
				xl = JSON.parse(xl);
				if(xl){
					for(var m = 0; m < xl.length; m++) {
						if(xl[m].id == xsdwindid) {
							xl.splice(m, 1);
							plus.storage.setItem('xl', JSON.stringify(xl));
						}
					}
				}
			}
			
			function deleteXlChild(){
				var xlchild = plus.storage.getItem('xlchild');
				xlchild = JSON.parse(xlchild);
				if(xlchild){
					for(var i = 0; i < xlchild.length; i++) {
						if(xlchild[i].key == xsdwindid) {
							xlchild.splice(i, 1);
							plus.storage.setItem('xlchild', JSON.stringify(xlchild));
						}
					}
				}
				console.log('线路.....'+JSON.stringify(xlchild));
			}
			
			function getTime(){
				var myDate = new Date(); //保存的日期时间
				var year = myDate.getFullYear(); //年
				var month = myDate.getMonth() + 1;
				var day = myDate.getDate();
				var hour = myDate.getHours(); //获取当前小时数(0-23)
				var mins = myDate.getMinutes(); //获取当前分钟数(0-59)
				var second = myDate.getSeconds(); //获取当前秒数(0-59)
				var months = (month < 10) ? ("0" + month) : month;
				var days = (day < 10) ? ("0" + day) : day;
				var hours = (hour < 10) ? ("0" + hour) : hour;
				var minss = (mins < 10) ? ("0" + mins) : mins;
				var seconds = (second < 10) ? ("0" + second) : second;
				console.log("月。。" + month + "日" + day.length)
				var smTime = year + "-" + months + "-" + days + " " + hours + ":" + minss + ":" + seconds;
				return smTime;
			}

			function Alert() {
				$(".mui-card-header").on("tap", ".title", function() {
					var Text = $(this).text()
					mui.alert(Text, '巡检设备名称', function() {});
				})
			}
			$('#sure').on('tap', function() {
				console.log('dataArr',dataArr);
				if (dataArr != '') {
					mui.openWindow({
						id: "reason.html",
						url: "reason.html",
						waiting: {
							autoShow: false, //自动显示等待框，默认为true
						},
						extras: {
							Idarr: dataArr,
							xjtype:xjtype,
							xsdwindid:xsdwindid
						}
					});
				} else {
					mui.toast('请选择！');
				}
			})
		</script>
	</body>

</html>
